/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MemberInformationPanel.java
 *
 * Created on Jul 12, 2011, 6:13:22 PM
 */
package panels;

import conn.EMIS4Connection;
import dao.LoginDao;
import dao.PersonDao;
import dao.PhoneDao;
import dao.SexDao;
import exec.NotFoundException;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import obj.Login;
import obj.Person;
import obj.Phone;
import obj.Sex;
import util.EMISUtil;
import util.LoggedInUser;
import util.PersonRequested;

/**
 * @author nknowles
 */
public class MemberInformationPanel extends javax.swing.JPanel {

  private Login login;
  private LoginDao loginDAO;
  private Person person;
  private PersonDao personDAO;
  private Phone phone;
  private PhoneDao phoneDAO;
  private List<Phone> phoneList;
  private Sex sex;
  private SexDao sexDAO;
  private int userID;
  
  LoggedInUser loggedInUser = LoggedInUser.getInstance();
  EMIS4Connection conn = EMIS4Connection.getInstance();

  /** Creates new form MemberInformationPanel */
  public MemberInformationPanel() {
    initComponents();
    login = new Login();
    loginDAO = new LoginDao();
    person = new Person();
    personDAO = new PersonDao();
    phone = new Phone();
    phoneDAO = new PhoneDao();
    sex = new Sex();
    sexDAO = new SexDao();

    fillInformation();
  }

  private void fillInformation() {
    PersonRequested personRequested = PersonRequested.getInstance();
    if(personRequested.getPerson() == null || personRequested.getPerson().getPersonID() == 0)
        userID = loggedInUser.getUserID();
    else
        userID = personRequested.getPerson().getPersonID();
    phone.setPersonID(userID);

    conn.connect();
    try {
      // get objects from database
      login = loginDAO.getObject(conn.getConnection(), userID);
      person = personDAO.getObject(conn.getConnection(), userID);
      phoneList = phoneDAO.searchMatching(conn.getConnection(), phone);
      sex = sexDAO.getObject(conn.getConnection(), person.getSexID());
    } catch (NotFoundException ex) {
      Logger.getLogger(MemberInformationPanel.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
      Logger.getLogger(MemberInformationPanel.class.getName()).log(Level.SEVERE, null, ex);
    }

    // fill out info
    usernameLabel.setText(login.getUsername());
    fNameLabel.setText(person.getFirstName());
    lNameLabel.setText(person.getLastName());
    dobLabel.setText(person.getDOB().toString().substring(0, 10));
    ssnLabel.setText(EMISUtil.convertSsnString(person.getSSN()));
    emailLabel.setText(person.getEmail());
    mariedStatusLabel.setText(person.getMaritalStatus());
    bloodTypeLabel.setText(person.getBloodType());
    switch (phoneList.size()) {
      case 2:
        phone2Label.setText(EMISUtil.convertPhoneString(phoneList.get(1).getNumber()));
      case 1:
        phone1Label.setText(EMISUtil.convertPhoneString(phoneList.get(0).getNumber()));
    }
    sexLabel.setText(sex.getName());
  }

  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {
    java.awt.GridBagConstraints gridBagConstraints;

    jLabel6 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel9 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jLabel7 = new javax.swing.JLabel();
    jLabel8 = new javax.swing.JLabel();
    jLabel1 = new javax.swing.JLabel();
    usernameLabel = new javax.swing.JLabel();
    fNameLabel = new javax.swing.JLabel();
    lNameLabel = new javax.swing.JLabel();
    dobLabel = new javax.swing.JLabel();
    ssnLabel = new javax.swing.JLabel();
    emailLabel = new javax.swing.JLabel();
    phone1Label = new javax.swing.JLabel();
    phone2Label = new javax.swing.JLabel();
    sexLabel = new javax.swing.JLabel();
    jLabel10 = new javax.swing.JLabel();
    jLabel11 = new javax.swing.JLabel();
    jLabel12 = new javax.swing.JLabel();
    mariedStatusLabel = new javax.swing.JLabel();
    bloodTypeLabel = new javax.swing.JLabel();

    setBackground(new java.awt.Color(220, 220, 210));
    setLayout(new java.awt.GridBagLayout());

    jLabel6.setText("Email:");
    jLabel6.setName("jLabel6"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 6;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(10, 25, 0, 0);
    add(jLabel6, gridBagConstraints);

    jLabel5.setText("SSN:");
    jLabel5.setName("jLabel5"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 5;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(10, 25, 0, 0);
    add(jLabel5, gridBagConstraints);

    jLabel4.setText("DOB:");
    jLabel4.setName("jLabel4"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 4;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(10, 25, 0, 0);
    add(jLabel4, gridBagConstraints);

    jLabel3.setText("Last Name:");
    jLabel3.setName("jLabel3"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(10, 25, 0, 0);
    add(jLabel3, gridBagConstraints);

    jLabel9.setText("Sex:");
    jLabel9.setName("jLabel9"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 9;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(10, 25, 0, 0);
    add(jLabel9, gridBagConstraints);

    jLabel2.setText("First Name:"); // NOI18N
    jLabel2.setName("jLabel2"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(10, 25, 0, 0);
    add(jLabel2, gridBagConstraints);

    jLabel7.setText("Phone1:");
    jLabel7.setName("jLabel7"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 7;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(10, 25, 0, 0);
    add(jLabel7, gridBagConstraints);

    jLabel8.setText("Phone2:");
    jLabel8.setName("jLabel8"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 8;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(10, 25, 0, 0);
    add(jLabel8, gridBagConstraints);

    jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24));
    jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel1.setText("Member Information Page");
    jLabel1.setName("jLabel1"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.weightx = 0.1;
    gridBagConstraints.insets = new java.awt.Insets(10, 15, 0, 0);
    add(jLabel1, gridBagConstraints);

    usernameLabel.setName("usernameLabel"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
    add(usernameLabel, gridBagConstraints);

    fNameLabel.setName("fNameLabel"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
    add(fNameLabel, gridBagConstraints);

    lNameLabel.setName("lNameLabel"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
    add(lNameLabel, gridBagConstraints);

    dobLabel.setName("dobLabel"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 4;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
    add(dobLabel, gridBagConstraints);

    ssnLabel.setName("ssnLabel"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 5;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
    add(ssnLabel, gridBagConstraints);

    emailLabel.setName("emailLabel"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 6;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
    add(emailLabel, gridBagConstraints);

    phone1Label.setName("phone1Label"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 7;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
    add(phone1Label, gridBagConstraints);

    phone2Label.setName("phone2Label"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 8;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
    add(phone2Label, gridBagConstraints);

    sexLabel.setName("sexLabel"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 9;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
    add(sexLabel, gridBagConstraints);

    jLabel10.setText("User Name:");
    jLabel10.setName("jLabel10"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(10, 25, 0, 0);
    add(jLabel10, gridBagConstraints);

    jLabel11.setText("Martial Status:");
    jLabel11.setName("jLabel11"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 10;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(10, 25, 0, 0);
    add(jLabel11, gridBagConstraints);

    jLabel12.setText("Blood Type:");
    jLabel12.setName("jLabel12"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 11;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.weighty = 0.1;
    gridBagConstraints.insets = new java.awt.Insets(10, 25, 10, 0);
    add(jLabel12, gridBagConstraints);

    mariedStatusLabel.setName("mariedStatusLabel"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 10;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
    add(mariedStatusLabel, gridBagConstraints);

    bloodTypeLabel.setName("bloodTypeLabel"); // NOI18N
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 11;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
    add(bloodTypeLabel, gridBagConstraints);
  }// </editor-fold>//GEN-END:initComponents
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JLabel bloodTypeLabel;
  private javax.swing.JLabel dobLabel;
  private javax.swing.JLabel emailLabel;
  private javax.swing.JLabel fNameLabel;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel10;
  private javax.swing.JLabel jLabel11;
  private javax.swing.JLabel jLabel12;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  private javax.swing.JLabel jLabel5;
  private javax.swing.JLabel jLabel6;
  private javax.swing.JLabel jLabel7;
  private javax.swing.JLabel jLabel8;
  private javax.swing.JLabel jLabel9;
  private javax.swing.JLabel lNameLabel;
  private javax.swing.JLabel mariedStatusLabel;
  private javax.swing.JLabel phone1Label;
  private javax.swing.JLabel phone2Label;
  private javax.swing.JLabel sexLabel;
  private javax.swing.JLabel ssnLabel;
  private javax.swing.JLabel usernameLabel;
  // End of variables declaration//GEN-END:variables
}
